import React, { useState ,useEffect} from 'react';
import axios from 'axios';
import AppBar from '@mui/material/AppBar';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Grid';
import Button from '@mui/material/Button';
import TextField from '@mui/material/TextField';
import IconButton from '@mui/material/IconButton';
import SearchIcon from '@mui/icons-material/Search';
import RefreshIcon from '@mui/icons-material/Refresh';
import ListSubheader from '@mui/material/ListSubheader';
import List from '@mui/material/List';
import ListItemButton from '@mui/material/ListItemButton';
import ListItemIcon from '@mui/material/ListItemIcon';
import ListItemText from '@mui/material/ListItemText';
import Collapse from '@mui/material/Collapse';
import InboxIcon from '@mui/icons-material/MoveToInbox';
import DraftsIcon from '@mui/icons-material/Drafts';
import SendIcon from '@mui/icons-material/Send';
import ExpandLess from '@mui/icons-material/ExpandLess';
import ExpandMore from '@mui/icons-material/ExpandMore';
import StarBorder from '@mui/icons-material/StarBorder';
import { LineChart, CartesianGrid, XAxis, YAxis, Tooltip, Legend, Line } from 'recharts';
import PersonIcon from '@mui/icons-material/Person';
import ShowChartIcon from '@mui/icons-material/ShowChart';
import Box from '@mui/material/Box';
import Input from '@mui/material/Input';

const ariaLabel = { 'aria-label': 'description' };
let data1 = [];
const data = [
  {
    name: '6.7',
       uv: 6,
    
    
  },
  {
    name: '6.8',
    uv: 7,
    
  },
  {
    name: '6.9',
    uv:9,
   
  },
  {
    name: '6.10',
    
    pv: 8,
    
  },
  {
    name: '6.11',
   
    pv: 8,
    
  },
 
];


export default function Content() {
  const [open, setOpen] = React.useState(true);
  const [rows2, setRows2] = useState([]);
  const [rows1, setRows1] = useState(0);
  const [formData, setFormData] = useState({
    amount: ''
  });

  const data_stock = new FormData();
  data_stock.append('stockname', '秦安股份');

  useEffect(() => {
  axios.post('http://172.24.56.192:5000/index/display_stockprice',data_stock,{headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
            }})
              .then(function (response) {
                  // 这里是处理响应的代码
                // var code = response['code']
                setRows2(response.data['data']);
                setRows1(response.data['price']);
                console.log(response.data);
                console.log(rows1);
                  
              })
              .catch(function (error) {
                  // 这里是处理错误的代码
                // window.location.href="https://www.baidu.com/"
                  console.log(error);
                
              });},[]);

            
 
  const purse_stock = new FormData();
 

  const handleClick = () => {
    setOpen(!open);

    let value = formData.amount;
    purse_stock.append('amount',value);
    purse_stock.append('stockname','秦安股份');
    console.log(value);
    console.log(purse_stock);
    console.log(data_stock);

    axios.post('http://172.24.56.192:5000/index/display_stockprice', purse_stock,{headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
      }})
      .then(response => {
        // 处理成功响应
        console.log(purse_stock);
        console.log(response.data);
        if(response.data['code'] == 200)
        {
            alert('Success')
            window.location.href="AppHome_Inv"           
        }
        //window.location.href="AppHome_Aut_2";
        // 在这里进行其他操作，如更新状态、显示成功提示等
      })
      .catch(error => {
        // 处理错误
        console.error(error);
        // 在这里进行其他操作，如显示错误提示等
      });





  };

  const handleInputChange = (event) => {
    const { name, value } = event.target;
    setFormData(prevState => ({
      ...prevState,
      [name]: value
    }));
  };

  return (
    <Paper sx={{ maxWidth: 2000, margin: 'auto', overflow: 'hidden' }}>
      
          <List
            sx={{ width: '100%', maxWidth: 2000, bgcolor: 'background.paper' }}
            component="nav"
            aria-labelledby="nested-list-subheader"
          >
            <Grid container spacing={2}>
              <Grid item xs={2}> 
                <ListItemButton>
                  <ListItemIcon>
                    <ShowChartIcon />
                  </ListItemIcon>
                  <ListItemText primary="Stocks" />  
                </ListItemButton>
                <ListItemButton sx={{ pl: 6 }}  >
                  <ListItemText primary="秦安股份"primaryTypographyProps={{color: 'primary'}}/>  
                </ListItemButton>
                <ListItemButton sx={{ pl: 6 }} href='AppHome_Inv_stock1'>
                  <ListItemText primary="弘讯科技" />  
                </ListItemButton>
                <ListItemButton sx={{ pl: 6 }} href='AppHome_Inv_stock2'>
                  <ListItemText primary="合力科技"/>  
                </ListItemButton>
                <ListItemButton sx={{ pl: 6 }} href='AppHome_Inv_stock3'>
                  <ListItemText primary="洛阳玻璃"/>  
                </ListItemButton>
                <ListItemButton sx={{ pl: 6 }} href='AppHome_Inv_stock4'>
                  <ListItemText primary="金辰股份"/>  
                </ListItemButton>
                <ListItemButton sx={{ pl: 6 }} href='AppHome_Inv_stock5'>
                  <ListItemText primary="博迁新材"/>  
                </ListItemButton>
                <ListItemButton sx={{ pl: 6 }} href='AppHome_Inv_stock6'>
                  <ListItemText primary="汇得科技"/>  
                </ListItemButton>
                <ListItemButton sx={{ pl: 6 }} href='AppHome_Inv_stock7'>
                  <ListItemText primary="紫江企业"/>  
                </ListItemButton>
                <ListItemButton sx={{ pl: 6 }} href='AppHome_Inv_stock8'>
                  <ListItemText primary="福莱新材"/>  
                </ListItemButton>
                <ListItemButton sx={{ pl: 6 }} href='AppHome_Inv_stock9'>
                  <ListItemText primary="华鑫股份"/>  
                </ListItemButton>
                <ListItemButton sx={{ pl: 6 }} href='AppHome_Inv_stock10'>
                  <ListItemText primary="金晶科技"/>  
                </ListItemButton>
                <ListItemButton sx={{ pl: 6 }} href='AppHome_Inv_stock11'>
                  <ListItemText primary="安彩高科"/>  
                </ListItemButton>
                <ListItemButton sx={{ pl: 6 }} href='AppHome_Inv_stock12'>
                  <ListItemText primary="南京熊猫"/>  
                </ListItemButton>
                <ListItemButton sx={{ pl: 6 }} href='AppHome_Inv_stock13'>
                  <ListItemText primary="神马电力"/>  
                </ListItemButton>
                <ListItemButton sx={{ pl: 6 }} href='AppHome_Inv_stock14'>
                  <ListItemText primary="同达创业"/>  
                </ListItemButton>

                
              </Grid> 


              <Grid item xs={6}>
                <ListItemButton>
                  <ListItemText primary=" " primaryTypographyProps={{color: 'primary'}}/>  
                  <ListItemText primary=" "/> 
                </ListItemButton>
                <ListItemButton>
                  <ListItemText primary=" " primaryTypographyProps={{color: 'primary'}}/>  
                  <ListItemText primary=" "/> 
                </ListItemButton>
                <LineChart
                  width={820}
                  height={350}
                  data={rows2}
                  margin={{
                    top: 10,
                    right: 30,
                    left: 0,
                    bottom: 5,
                  }}
                >
                  <CartesianGrid strokeDasharray="3 3" />
                  <XAxis dataKey="name" />
                  <YAxis domain={[8, 11]}/>
                  <Tooltip />
                  <Legend />
                  <Line type="monotone" dataKey="price" stroke="#8884d8" activeDot={{ r: 8 }} />
                  <Line type="monotone" dataKey="predict_price" stroke="#FA7F6F"  />
                </LineChart>
                <Button></Button>
                <ListItemButton>
                   <ListItemText primary="Introduction: " primaryTypographyProps={{color: 'primary'}}/> 
                </ListItemButton>
                <Typography sx={{ pl: 6 }}>
                秦安股份专注工业自动化行业三十多年,依托台湾地区的科技和产业优势,与国内优秀团队的共同努力,积累了深厚的技术底蕴和行业经验。 掌
                握运动控制技术、工业总线技术、伺服驱动技术、工业机器人技术等智能制造相关的软硬件核心技术,为海内外客户提供工业控制类、伺服系统类、机器人类产
                军培育企业”,连续被评为“中国塑料机械行业优势企业”。 公司上市后,于2016年收购意大利EEI,进入新能源行业。
                </Typography>
                <ListItemButton>
                   <ListItemText primary="advise: " primaryTypographyProps={{color: 'primary'}}/> 
                </ListItemButton>
                <Typography sx={{ pl: 6 }}>
                中等看好。建议偏激理财者购买。秦安股份专注工业自动化行业三十多年,依托台湾地区的科技和产业优势,与国内优秀团队的共同努力,积累了深厚的技术底蕴和行业经验。
                </Typography>
              </Grid>  

              <Grid item xs>
                <ListItemButton>
                  <ListItemText primary="Price:" primaryTypographyProps={{color: 'primary'}}/>  
                  <Typography>
                    {rows1}　　　　　　　　　　　　
                  
                 </Typography>
                </ListItemButton>



                <ListItemButton>
                  <ListItemText primary="" primaryTypographyProps={{color: 'primary'}}/>  
                </ListItemButton>



                <Box
                   component="form"
                   sx={{
                     '& > :not(style)': { m: 1 },
                     pl: 27
                   }}
                   noValidate
                   autoComplete="off"
                 >
                   <Input 
                    placeholder="Amount"
                    name="amount"
                    value={formData.amount}
                    onChange={handleInputChange} 
                   />
                </Box>

                 
                
                <Button></Button>
                <Button></Button>
                <Button></Button>
                <Button></Button>
                <Button variant="outlined" color="success" onClick={handleClick}>
                 Purchase
                </Button>

              </Grid>



            </Grid>
            
          </List>



          
    </Paper>
  );
}

